import 'dart:convert';

import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:nb_utils/nb_utils.dart';
import 'package:pitchertools/http/dio_http.dart';

import 'index.dart';

///用户页面
class UserPage extends GetView<UserPageController> {
  const UserPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return Column(
      children: [
        Obx(() {
          var imgByteData = controller.state.imgByteData;
          if (imgByteData == "") {
            return GFButton(
                text: "获取验证码",
                onPressed: () async {
                  controller.getImgByteData();
                });
          }
          final byteData = base64Decode(controller.state.imgByteData);
          return Image.memory(byteData).onTap(() {
            controller.getImgByteData();
          });
        }),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserPageController>(
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
